package com.zhs.gccs.http;

import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * //            HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger(){
 * //
 * //                private Logger logger = LoggerFactory.getLogger("OKHttpClient");
 * //                private StringBuilder sb = new StringBuilder("\n");
 * //
 * //                @Override
 * //                public void log(String msg) {
 * //                    sb.append(msg).append("\n");
 * //                    if (msg.startsWith("<-- END HTTP")) {
 * //                        logger.info(sb.toString());
 * //                        System.out.println(sb.toString());
 * //                        sb = new StringBuilder("\n");
 * //                    }
 * //
 * //                }
 * //            });
 * //            logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
 */

public class OkHttpLogger implements HttpLoggingInterceptor.Logger {
    private static final Logger logger = LoggerFactory.getLogger(OkHttpLogger.class);
    private static final String TAG = "OkHttp";
    private StringBuilder sb = new StringBuilder("\n");

    @Override
    public void log(String msg) {
        sb.append(msg).append("\n");
        if (msg.startsWith("<-- END HTTP")) {
            logger.info(sb.toString());
            System.out.println(sb.toString());
            sb = new StringBuilder("");
        }
    }
}
